//
//  chooseMarriedVC.m
//  YiXiu
//
//  Created by ZHY on 16/7/17.
//  Copyright © 2016年 zzz. All rights reserved.
//
//
//#import "chooseMarriedVC.h"
//
//@interface chooseMarriedVC ()
//
//@end
//
//@implementation chooseMarriedVC

#import "chooseMarriedVC.h"
#import "EventBaseSettingViewController.h"

@interface chooseMarriedVC ()

//#define sexX  0
//#define sexY  84
//#define sexW  KScreenWidth - sexX*2
//#define sexH  40


//@property (nonatomic, strong) UIButton *oppositeSex;
//@property (nonatomic, strong) UIButton *gayBtn;
//@property (nonatomic, strong) UIButton *doubleBtn;
//
////这只是一条无情的分割线
//@property (nonatomic, strong) UIImageView *lineView;
//@property (nonatomic, strong) UIImageView *lineTowView;


@property (nonatomic, assign) __block BOOL image1Hidden;
@property (nonatomic, assign) __block BOOL image2Hidden;
@property (nonatomic, assign) __block BOOL image3Hidden;

@property(nonatomic, weak) UIButton * rigth;


@end

@implementation chooseMarriedVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = UIColorFromRGB(0xefeff4);
    
    
    self.image1Hidden = YES;
    self.image2Hidden = YES;
    self.image3Hidden = YES;
    
    [self addThreeGroupWithRefreshData:NO];

    [self setUpRightBtn];
    
    
    
}

- (void)setBlock:(marBlock)block{
    _block = block;
}


-(void)addThreeGroupWithRefreshData:(BOOL)isOK
{
    
    EventSettingItem *setting = [EventSettingItem itemWithText:@"已婚" image:nil type:EventSettingItemTypeSelectArrow viewTag:buildScheduleType arrowImageName:@"guoguo" isArrowHidden:self.image1Hidden];
    
    setting.operation = ^{
        self.image1Hidden = NO;
        self.image2Hidden = YES;
        self.image3Hidden = YES;
        
        
        
        [self.tableView reloadData];
        [self addThreeGroupWithRefreshData:YES];
    };
    
    EventSettingItem *setting1 = [EventSettingItem itemWithText:@"未婚" image:nil type:EventSettingItemTypeSelectArrow viewTag:buildScheduleType arrowImageName:@"guoguo" isArrowHidden:self.image2Hidden];
    setting1.operation = ^{
        self.image1Hidden = YES;
        self.image2Hidden = NO;
        self.image3Hidden = YES;
        
        [self.tableView reloadData];
        [self addThreeGroupWithRefreshData:YES];
    };
    
    
    EventSettingItem *setting2 = [EventSettingItem itemWithText:@"单身" image:nil type:EventSettingItemTypeSelectArrow viewTag:buildScheduleType arrowImageName:@"guoguo" isArrowHidden:self.image3Hidden];
    
    setting2.operation = ^{
        self.image1Hidden = YES;
        self.image2Hidden = YES;
        self.image3Hidden = NO;
        
        [self.tableView reloadData];
        [self addThreeGroupWithRefreshData:YES];
    };
    
    EventSettingGroup *group = [[EventSettingGroup alloc] init];
    
    group.rowHeight = 60;
    
    group.items = @[setting,setting1,setting2];
    
    
    if (isOK) {
        [self.allGroups replaceObjectAtIndex:0 withObject:group];
    }else{
        [self.allGroups addObject:group];
    }
    
}


-(void)setUpRightBtn{
    
    UIButton * rightItem = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 64, 44)];
    self.rigth = rightItem;
    
    
    [rightItem addTarget:self action:@selector(releaseInfo:) forControlEvents:UIControlEventTouchUpInside];
    [rightItem setTitle:@"提交" forState:UIControlStateNormal];
    [rightItem setTitleColor:[UIColor grayColor] forState:UIControlStateSelected];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightItem];
    
    
}

-(void)releaseInfo:(UIButton *)sender{
    
   // __weak 弱引用 避免循环引用
    __weak typeof (self) weakSelf = self;
    if (weakSelf.block) {
        
        EventSettingItem * item = [[EventSettingItem alloc]init];
        
        if (item.selectedIndex == 0) {
            weakSelf.block(@"已婚");
        }else if(item.selectedIndex == 1){
            weakSelf.block(@"未婚");
        }else{
            weakSelf.block(@"单身");
        }
        
        NSLog(@"%ld",item.selectedIndex);
    }
    
    //传出block
    if (self.image1Hidden == NO) {
        if (self.block) {
            self.block(@"已婚");
        }
    }else if (self.image2Hidden == NO){
        if (self.block) {
            self.block(@"未婚");
        }
    }else if (self.image3Hidden == NO){
        if (self.block) {
            self.block(@"单身");
        }
    }
    
    
    [self.navigationController popViewControllerAnimated:YES];
    
}





@end
